<template>
  <div class="index" v-cloak>
    <!-- 首页顶部位置改动：banner图+ -->
    <div class="header acea-row row-center-wrapper">
      <div class="row">
        <!-- logo去掉改成门店定位，5KM内没有实体店，定位到总店 -->
        <div class="select" v-text="locat"></div>
        <router-link :to="'/search'" class="search acea-row row-middle">
          <span class="iconfont icon-xiazai5"></span>搜索您要的商品
        </router-link>
        <img src="@/assets/imgs/msg.png" />
      </div>
      <div class="banner_index">
        <!-- <div class="banner_text">推荐有奖</div>
        <div>入驻加盟合作共赢</div> -->
      </div>
    </div>
      <!-- 原轮播图位置：假数据 -->
      <!-- <div class="slider-banner banner">
        <swiper :options="swiperOption">
          <swiper-slide>
            <img src="@/assets/imgs/bannerone.jpg" />
          </swiper-slide>
          <swiper-slide>
            <img src="@/assets/imgs/bannertwo.jpg" />
          </swiper-slide>
          <div class="swiper-pagination" slot="pagination"></div>
        </swiper>
      </div> -->
      <!-- 新增福利大放送按钮 -->
    <div class="fuli">
      <div class="font">
        <p class="font_title">福利大放送</p>
        <p class="font_detail">购物领红包，拿返利</p>
      </div>
      <div class="font_go">GO</div>
    </div>
    <!-- 商品分类 -->
    <!-- <div class="nav acea-row">
      <router-link
        :to="item.wap_url ? item.wap_url : ''"
        class="item"
        v-for="(item, index) in menu"
        :key="index"
      >
        <div class="pictrue"><img :style="{boxShadow:'0.05rem 0.02rem 0.15rem '+item.color}" :src="item.pic" /></div>
        <div>{{ item.name }}</div>
      </router-link>
      <router-link
        :to="item.wap_url ? item.wap_url : ''"
        class="item"
        v-for="(item, index) in menus"
        :key="index"
      >
        <div class="pictrue"><img :style="{boxShadow:'0.05rem 0.02rem 0.15rem '+item.color}" :src="item.pic" /></div>
        <div>{{ item.name }}</div>
      </router-link>
    </div> -->
    <div class="nav acea-row">
      <router-link to="/category" class="item">
        <div class="pictrue"><img src="@assets/imgs/商品分类.png" /></div>
        <div>商品分类</div>
      </router-link>
      <router-link to="/user/get_coupon" class="item">
        <div class="pictrue"><img src="@assets/imgs/领优惠券.png" /></div>
        <div>领优惠券</div>
      </router-link>
      <router-link to="/news_list" class="item">
        <div class="pictrue"><img src="@assets/imgs/行业资讯.png" /></div>
        <div>行业资讯</div>
      </router-link>
      <router-link to="user/sign" class="item">
        <div class="pictrue"><img src="@assets/imgs/我要签到.png" /></div>
        <div>我要签到</div>
      </router-link>
      <router-link to="/goods_list?id=21&title=数码产品" class="item">
        <div class="pictrue"><img src="@assets/imgs/数码产品.png" /></div>
        <div>数码产品</div>
      </router-link>
      <router-link to="/goods_list?id=21&title=建材产品" class="item">
        <div class="pictrue"><img src="@assets/imgs/建材产品.png" /></div>
        <div>建材产品</div>
      </router-link>
      <router-link to="/goods_list?id=21&title=潮流服饰" class="item">
        <div class="pictrue"><img src="@assets/imgs/潮流服饰.png" /></div>
        <div>潮流服饰</div>
      </router-link>
      <router-link to="/goods_list?id=21&title=生鲜到家" class="item">
        <div class="pictrue"><img src="@assets/imgs/生鲜到家.png" /></div>
        <div>生鲜到家</div>
      </router-link>
    </div>
    <!-- 新闻竖行轮播 -->
    <div class="news acea-row row-between-wrapper">
      <div class="pictrue">
        <!-- 图片换成新文案 -->
        <p><span>平台</span><span class="span">公告</span></p>
        <!-- <img src="@assets/images/news.png" /> -->
      </div>
      <div class="swiper-no-swiping new-banner">
        <swiper
          class="swiper-wrapper"
          :options="swiperRoll"
          v-if="roll.length > 0"
        >
          <swiper-slide
            class="swiper-slide"
            v-for="(item, index) in roll"
            :key="index"
          >
            <router-link
              :to="item.wap_url ? item.wap_url : ''"
              class="acea-row row-between-wrapper"
            >
              <div class="text acea-row row-between-wrapper">
                <div class="label" v-if="item.show === '是'">最新</div>
                <div class="newsTitle line1">{{ item.info }}</div>
              </div>
              <div class="iconfont icon-xiangyou"></div>
            </router-link>
          </swiper-slide>
        </swiper>
      </div>
    </div>
    <div
      class="specialArea acea-row row-between-wrapper"
      v-if="activity.length"
    >
      <!-- 原banner三组设计（主图位置） -->
      <!-- <router-link
        :to="activityOne.wap_link ? activityOne.wap_link : ''"
        class="assemble"
      >
        <img :src="activityOne.pic" />
        <div class="text">
          <div class="name">{{ activityOne.title }}</div>
          <div class="infor">{{ activityOne.info }}</div>
        </div>
      </router-link> -->
      <div class="title acea-row row-between-wrapper">
        <div class="text">
          <div class="name line1">实时优惠活动</div>
        </div>
        <div class="more"
          >最近发布4个活动</div>
      </div>
      <!-- <div class="list acea-row row-column-between">
        <router-link
          :to="item.wap_link ? item.wap_link : ''"
          class="item"_normalized
          v-for="(item, index) in activity"
          :key="index"
        >
          <img :src="item.pic" />
          <div class="text">
            <div class="name">{{ item.title }}</div>
            <div class="infor">{{ item.info }}</div>
          </div>
        </router-link> -->


        <!-- 发布活动 -->
        <!-- <router-link
          :to="item.wap_link ? item.wap_link : ''"
          class="item"
          v-for="(item, index) in activity"
          :key="index"
        >
        <div class="list">
          <img :src="item.pic" /> 
          <div class="text">
            <div class="name" :style="{color:item.color}"
            >{{ item.title }}</div>
            <div class="infor">{{ item.info }}</div>
          </div>
        </div>
        <div class="red_title" v-if="item.red_title.length>0">{{item.red_title}}</div>
        </router-link> -->
        <router-link to="activity/bargain" class="item">
        <div class="list">
          <img src="@assets/imgs/秒杀.png" />
          <div class="text">
            <div class="name" style="color:#fe8d31"
            >砍价专区</div>
            <div class="infor">呼朋唤友来砍价</div>
          </div>
        </div>
        </router-link>
        <router-link to="activity/group" class="item">
        <div class="list">
          <img src="@assets/imgs/团购.png" />
          <div class="text">
            <div class="name" style="color:#63c6ff"
            >团购专区</div>
            <div class="infor">优惠多多</div>
          </div>
        </div>
        </router-link>
        <router-link to="/activity/goods_seckill" class="item">
        <div class="list">
          <img src="@assets/imgs/限时购.png" />
          <div class="text">
            <div class="name" style="color:#ff405f"
            >秒杀专区</div>
            <div class="infor">天天特价</div>
          </div>
        </div>
        <div class="red_title">国际大牌专场···</div>
        </router-link>
        <router-link to="/activity/Appointment" class="item">
        <div class="list">
          <img src="@assets/imgs/预约.png" />
          <div class="text">
            <div class="name" style="color:#2acb8c"
            >预约专场</div>
            <div class="infor">提前预约</div>
          </div>
        </div>
        <div class="red_title">提前预约专场···</div>
        </router-link>
      <!-- </div> -->
    </div>
   <div class="wrapper" v-if="info.fastList.length > 0">
      <div class="title acea-row row-between-wrapper">
        <div class="text">
          <div class="name line1">快速选择</div>
          <div class="line1">{{ info.fastInfo }}</div>
        </div>
        <router-link :to="'/category'" class="more"
          >更多<span class="iconfont icon-jiantou"></span
        ></router-link>
      </div>
      <div class="scroll-product">
        <swiper class="swiper-wrapper" :options="swiperScroll">
          <swiper-slide
            v-for="(item, index) in info.fastList"
            :key="index"
            class="swiper-slide"
          >
            <router-link
              :to="{
                path: '/goods_list',
                query: { id: item.id, title: item.cate_name }
              }"
            >
              <div class="img-box">
                <img :src="item.pic" />
              </div>
              <div class="pro-info line1">{{ item.cate_name }}</div>
            </router-link>
          </swiper-slide>
        </swiper>
      </div>
    </div>
    <div class="wrapper" v-if="info.bastList.length > 0">
      <div class="title acea-row row-between-wrapper">
        <div class="text">
          <div class="name line1">精品推荐</div>
          <div class="line1">{{ info.bastInfo }}</div>
        </div>
        <router-link :to="{ path: '/hot_new_goods/' + 1 }" class="more"
          >更多<span class="iconfont icon-jiantou"></span
        ></router-link>
      </div>
      <div class="slider-banner boutique">
        <swiper class="swiper-wrapper" :options="swiperBoutique">
          <swiper-slide class="swiper-slide">
            <router-link to="/hot_new_goods/1">
              <img src="@/assets/imgs/bannerone.jpg" />
            </router-link>
          </swiper-slide>
          <swiper-slide class="swiper-slide">
            <router-link to="/hot_new_goods/1">
              <img src="@/assets/imgs/bannertwo.jpg" />
            </router-link>
          </swiper-slide>
        </swiper>
        <div class="swiper-pagination"></div>
      </div>
      <Good-list :good-list="info.bastList" :is-sort="false"></Good-list>
    </div>
    <div class="hotList" v-if="likeInfo.length > 0">
      <div class="hot-bg">
        <div class="title acea-row row-between-wrapper">
          <div class="text line1">
            <span class="label">热销商品</span>根据销量、搜索、好评等综合得出
          </div>
          <router-link :to="{ path: '/hot_new_goods/' + 2 }" class="more">
            更多<span class="iconfont icon-jiantou"></span>
          </router-link>
        </div>
      </div>
      <div class="list acea-row row-middle">
        <router-link
          :to="{ path: '/detail/' + item.id }"
          class="item"
          v-for="(item, index) in likeInfo"
          :key="index"
        >
          <div class="pictrue">
            <img :src="item.image" />
            <img
              src="@assets/images/one.png"
              class="numPic"
              v-if="index === 0"
            />
            <img
              src="@assets/images/two.png"
              class="numPic"
              v-else-if="index === 1"
            />
            <img
              src="@assets/images/three.png"
              class="numPic"
              v-else-if="index === 2"
            />
          </div>
          <div class="name line1">{{ item.store_name }}</div>
          <div class="money font-color-red">
            ￥<span class="num">{{ item.price }}</span>
          </div>
        </router-link>
      </div>
    </div>
    <div>
      <div class="adver">
        <img src="@/assets/imgs/banner.jpg"/>
      </div>
    </div>
    <div class="wrapper" v-if="info.firstList.length > 0">
      <div class="title acea-row row-between-wrapper">
        <div class="text">
          <div class="name line1">
            首发新品<span class="new font-color-red">NEW~</span>
          </div>
          <div class="line1">{{ info.firstInfo }}</div>
        </div>
        <router-link :to="{ path: '/hot_new_goods/' + 3 }" class="more"
          >更多<span class="iconfont icon-jiantou"></span
        ></router-link>
      </div>
      <div class="newProducts">
        <swiper class="swiper-wrapper" :options="swiperProducts">
          <swiper-slide
            class="swiper-slide"
            v-for="(item, index) in info.firstList"
            :key="index"
          >
            <router-link :to="{ path: '/detail/' + item.id }">
              <div class="img-box">
                <img :src="item.image" />
              </div>
              <div class="pro-info line1">{{ item.store_name }}</div>
              <div class="money font-color-red">￥{{ item.price }}</div>
            </router-link>
          </swiper-slide>
        </swiper>
      </div>
    </div>
    <div class="wrapper" v-if="benefit.length > 0">
      <div class="title acea-row row-between-wrapper">
        <div class="text">
          <div class="name line1">活动商品</div>
          <div class="line1">{{ info.salesInfo }}</div>
        </div>
        <router-link :to="'/promotion'" class="more"
          >更多<span class="iconfont icon-jiantou"></span
        ></router-link>
      </div>
    </div>
    <Promotion-good :benefit="benefit"></Promotion-good>
    <Coupon-window
      :coupon-list="couponList"
      v-if="showCoupon"
      @checked="couponClose"
      @close="couponClose"
    ></Coupon-window>
    <div style="height:1.2rem;"></div>
  </div>
</template>
<script>
import { swiper, swiperSlide } from "vue-awesome-swiper";
import "@assets/css/swiper.min.css";
import GoodList from "@components/GoodList";
import PromotionGood from "@components/PromotionGood";
import CouponWindow from "@components/CouponWindow";
import { getHomeData, getShare } from "@api/public";
import cookie from "@utils/store/cookie";
import { openShareAppMessage, openShareTimeline, ready } from "@libs/wechat";
import { isWeixin } from "@utils/index";
import { Row, Col,DropdownMenu, DropdownItem } from 'vant';
import {MP} from '@assets/js/map.js'

const HAS_COUPON_WINDOW = "has_coupon_window";

export default {
  name: "Index",
  components: {
    swiper,
    swiperSlide,
    GoodList,
    PromotionGood,
    CouponWindow
  },
  props: {},
  data: function() {
    return {
      locat:"",
      showCoupon: false,
      logoUrl: "",
      banner: [],
      menu: [
        {
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9ddc9f34bfd.png",
          name:"商品分类",
          color:"#ddd",
          wap_url:"/category"
        },{
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9ddccecb7f3.png",
          name:"领优惠券",
          color:"#ddd",
          wap_url:"/user/get_coupon"
        },{
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9ddcec57a80.png",
          name:"行业资讯",
          color:"#ddd",
          wap_url:"/news_list"
        },{
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9ddd570b8b3.png",
          name:"我要签到",
          color:"#ddd",
          wap_url:"user/sign"
        }
      ],
      menus:[
        {
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9dddce0eac9.png",
          name:"数码产品",
          color:"#ddd",
          wap_url:"/collection"
        },{
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9dde013f63c.png",
          name:"建材产品",
          color:"#ddd",
          wap_url:"/activity/group"
        },{
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9dde246ad96.png",
          name:"潮流服饰",
          color:"#ddd",
          wap_url:"/activity/goods_seckill"
        },{
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9ddedbed782.png",
          name:"生鲜到家",
          color:"#ddd",
          wap_url:"/activity/bargain"
        }
      ],
      roll: [
        {
          info:"知尔星电商系统 V 1.0 即将上线！",
          wap_url:"/news_list"
        }
      ],
      activity: [
        {
          wap_link:"/activity/bargain",
          color:"#fe8d31",
          title:"秒杀专区",
          info:"挑战全网最低价",
          red_title:"",
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/28/5c9ccf7e97660.jpg"
        },{
          wap_link:"/activity/group",
          color:"#63c6ff",
          title:"团购专区",
          info:"一人起团",
          red_title:"",
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/28/5c9ccfc86a6c1.jpg"
        },{
          wap_link:"/activity/goods_seckill",
          color:"#ff405f",
          title:"大牌限时购",
          info:"都很贵",
          red_title:"国际大牌专场···",
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/28/5c9ccf7e97660.jpg"
        },{
          wap_link:"/activity/Appointment",
          color:"#2acb8c",
          title:"预约专场",
          info:"提前预约",
          red_title:"提前预约专场···",
          pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/28/5c9ccfc86a6c1.jpg"
        }
      ],
      activityOne: {
        wap_link:"activity/group",
        title:"一起来拼团",
        info:"优惠多多",
        pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/28/5c9ccf7e9f4d0.jpg"
      },
      info: {
        fastInfo:"上百种商品分类任您选择",
        fastList: [
          {
            id:"7",
            pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9de8b7c5cc5.png",
            cate_name:"床垫",
          },{
            id:"2",
            pic:"http://datong.crmeb.net/public/uploads/attach/2019/01/15/5c3dba1366885.jpg",
            cate_name:"热门促销",
          },{
            id:"3",
            pic:"http://datong.crmeb.net/public/uploads/attach/2019/01/15/5c3dc0ef27068.jpg",
            cate_name:"折扣专区",
          },{
            id:"4",
            pic:"http://datong.crmeb.net/public/uploads/attach/2019/01/15/5c3dbc6a38fab.jpg",
            cate_name:"新品上线",
          },{
            id:"8",
            pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9def00c2882.png",
            cate_name:"灯具",
          },{
            id:"19",
            pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9def5fa968c.png",
            cate_name:"家具",
          },{
            id:"20",
            pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9df11e13742.png",
            cate_name:"床品件套",
          },{
            id:"21",
            pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9df170010cb.png",
            cate_name:"家饰花卉",
          },{
            id:"22",
            pic:"http://datong.crmeb.net/public/uploads/attach/2019/03/29/5c9df1b8f0a7a.png",
            cate_name:"布艺软装",
          },{
            id:"24",
            pic:"http://kaifa.crmeb.net/uploads/attach/2019/08/20190805/887db984b5f1138e08e1d9b069af766e.jpg",
            cate_name:"测试1",
          }
        ],
        bastInfo:"诚意推荐品质商品",
        bastBanner: [],
        firstInfo:"多个优质商品最新上架",
        firstList: [
          {
            id:"9",
            image:"http://activity.crmeb.net/public/uploads/attach/2019/05/29//51308e61ace45968fdef953b2ac6c241.jpg",
            store_name:"【雷神911Air星战】雷神(ThundeRobot)911Air星战二代旗舰版15.6英寸窄边框游戏笔记本电脑i79750H512GSSDRGB键盘GTX1650",
            price:"1000.00"
          },{
            id:"3",
            image:"http://datong.crmeb.net/public/uploads/attach/2019/01/15/5c3dc0ef27068.jpg",
            store_name:"智米加湿器 白色",
            price:"249.00"
          },{
            id:"2",
            image:"http://datong.crmeb.net/public/uploads/attach/2019/01/15/5c3dbc27c69c7.jpg",
            store_name:"智能马桶盖 AI版",
            price:"0.01"
          }
        ],
        salesInfo:"库存商品优惠促销活动",
        bastList: [
          {
            id:"11",
            image:"http://activity.crmeb.net/public/uploads/attach/2019/05/30//0eecbfbca9ebc315c2882590fd55a209.jpg",
            store_name:"伊利酸奶畅轻整箱装乳酸菌燕麦黄桃草莓早餐奶250克9瓶风味发酵乳",
            price:"80.00",
            vie_price:"",
            sales:"73",
            unit_name:"件"
          },{
            id:"7",
            image:"http://activity.crmeb.net/public/uploads/attach/2019/05/29//6f2a1ece45e307f274e3384410a3bd3a.jpg",
            store_name:"【华为畅享9S】华为HUAWEI畅享9S6GB+64GB珊瑚红全网通2400万超广角三摄珍珠屏大存储移动联通电信4G手机双卡双待",
            price:"100.00",
            vie_price:"",
            sales:"25",
            unit_name:"件"
          },{
            id:"3",
            image:"http://datong.crmeb.net/public/uploads/attach/2019/01/15/5c3dc0ef27068.jpg",
            store_name:"智米加湿器 白色",
            price:"249.00",
            vie_price:"",
            sales:"118",
            unit_name:"件"
          },{
            id:"2",
            image:"http://datong.crmeb.net/public/uploads/attach/2019/01/15/5c3dbc27c69c7.jpg",
            store_name:"智能马桶盖 AI版",
            price:"0.01",
            vie_price:"",
            sales:"232",
            unit_name:"件"
          }
        ]
      },
      likeInfo: [
        {
          id:"11",
          image:"http://activity.crmeb.net/public/uploads/attach/2019/05/30//0eecbfbca9ebc315c2882590fd55a209.jpg",
          store_name:"伊利酸奶畅轻整箱装乳酸菌燕麦黄桃草莓早餐奶250克9瓶风味发酵乳",
          price:"80.00"
        },{
          id:"9",
          image:"http://activity.crmeb.net/public/uploads/attach/2019/05/29//51308e61ace45968fdef953b2ac6c241.jpg",
          store_name:"【雷神911Air星战】雷神(ThundeRobot)911Air星战二代旗舰版15.6英寸窄边框游戏笔记本电脑i79750H512GSSDRGB键盘GTX1650",
          price:"1000.00"
        },{
          id:"8",
          image:"http://activity.crmeb.net/public/uploads/attach/2019/05/29//71e85589cb7d3398d08f0d55bdb9031d.jpg",
          store_name:"【AppleiPhone8】AppleiPhone8(A1863)256GB深空灰色移动联通电信4G手机",
          price:"0.00"
        }
      ],
      lovely: [],
      benefit: [
        {
          id:"3",
          image:"http://datong.crmeb.net/public/uploads/attach/2019/01/15/5c3dc0ef27068.jpg",
          store_name:"智米加湿器 白色",
          price:"249.00",
          ot_price:"299.00",
          stock:"3949",
          unit_name:"件"
        },{
          id:"2",
          image:"http://datong.crmeb.net/public/uploads/attach/2019/01/15/5c3dbc27c69c7.jpg",
          store_name:"智能马桶盖 AI版",
          price:"0.01",
          ot_price:"1999.00",
          stock:"938",
          unit_name:"件"
        }
      ],
      couponList: [],
      center: {lng: 116.5002310000, lat: 39.98170000000},
      headCenter:{lng:104.063591,lat:30.546242},
      distance:0,
      swiperOption: {
        pagination: {
          el: ".swiper-pagination",
          clickable: true
        },
        autoplay: {
          disableOnInteraction: false,
          delay: 2000
        },
        loop: true,
        speed: 1000,
        observer: true,
        observeParents: true
      },
      swiperRoll: {
        direction: "vertical",
        autoplay: {
          disableOnInteraction: false,
          delay: 2000
        },
        loop: true,
        speed: 1000,
        observer: true,
        observeParents: true
      },
      swiperScroll: {
        freeMode: true,
        freeModeMomentum: false,
        slidesPerView: "auto",
        observer: true,
        observeParents: true
      },
      swiperBoutique: {
        pagination: {
          el: ".swiper-pagination",
          clickable: true
        },
        autoplay: {
          disableOnInteraction: false,
          delay: 2000
        },
        loop: true,
        speed: 1000,
        observer: true,
        observeParents: true
      },
      swiperProducts: {
        freeMode: true,
        freeModeMomentum: false,
        slidesPerView: "auto",
        observer: true,
        observeParents: true
      }
    };
  },
  created(){
    // this.addressDetail();//仅获取当前定位方法
    // this.map();
    this.locationbtn();//获取当前定位并计算与指定坐标距离
  },
  mounted: function() {/*
    let that = this;
    getHomeData().then(res => {
      that.logoUrl = res.data.logoUrl;
      that.$set(that, "banner", res.data.banner);
      that.$set(that, "menus", res.data.menus);
      that.$set(that, "roll", res.data.roll);
      that.$set(that, "activity", res.data.activity);
      var activityOne = res.data.activity.shift() || {};
      that.$set(that, "activityOne", activityOne);
      that.$set(that, "info", res.data.info);
      that.$set(that, "likeInfo", res.data.likeInfo);
      that.$set(that, "lovely", res.data.lovely);
      that.$set(that, "benefit", res.data.benefit);
      that.$set(that, "couponList", res.data.couponList);
      that.setOpenShare();
      this.showCoupon =
        !cookie.has(HAS_COUPON_WINDOW) &&
        res.data.couponList.some(coupon => coupon.is_use);
    });*/
  },
  methods: {
    couponClose() {
      cookie.set(HAS_COUPON_WINDOW, 1);
    },
    setOpenShare: function() {
      getShare().then(res => {
        var data = res.data.data;
        var configAppMessage = {
          desc: data.synopsis,
          title: data.title,
          link: location.href,
          imgUrl: data.img
        };
        var configTimeline = {
          title: data.title,
          link: location.href,
          imgUrl: data.img
        };
        if (isWeixin() === true) {
          ready().then(() => {
            openShareAppMessage(configAppMessage).then(() => {});
            openShareTimeline(configTimeline).then(() => {});
          });
        }
      });
    },
    addressDetail(){ //获取地理位置
      var that=this;
      //全局的this在方法中不能使用，需要重新定义一下
      var geolocation = new BMap.Geolocation();
      var gc = new BMap.Geocoder();
      geolocation.getCurrentPosition( function(r) {   //定位结果对象会传递给r变量
        if(this.getStatus() == BMAP_STATUS_SUCCESS){  //通过Geolocation类的getStatus()可以判断是否成功定位。
          var pt = r.point;
          gc.getLocation(pt, function(rs){
            var addComp = rs.addressComponents;
            //这里的locat便是定位的地理位置
              let locat=(addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber);
              // console.log(locat);
              that.locat=locat;
              // console.log(that.locat);
            // vm.now = false
            //这里把位置存在session里面就可以在后面用了
            sessionStorage.setItem("dAddress",locat)
          });
        }else{
          //关于状态码
          //BMAP_STATUS_SUCCESS   检索成功。对应数值“0”。
          //BMAP_STATUS_CITY_LIST 城市列表。对应数值“1”。
          //BMAP_STATUS_UNKNOWN_LOCATION  位置结果未知。对应数值“2”。
          //BMAP_STATUS_UNKNOWN_ROUTE 导航结果未知。对应数值“3”。
          //BMAP_STATUS_INVALID_KEY   非法密钥。对应数值“4”。
          //BMAP_STATUS_INVALID_REQUEST   非法请求。对应数值“5”。
          //BMAP_STATUS_PERMISSION_DENIED 没有权限。对应数值“6”。(自 1.1 新增)
          //BMAP_STATUS_SERVICE_UNAVAILABLE   服务不可用。对应数值“7”。(自 1.1 新增)
          //BMAP_STATUS_TIMEOUT   超时。对应数值“8”。(自 1.1 新增)
          switch( this.getStatus() ){
            case 2:
              alert( '位置结果未知 获取位置失败.' );
              break;
            case 3:
              alert( '导航结果未知 获取位置失败..' );
              break;
            case 4:
              alert( '非法密钥 获取位置失败.' );
              break;
            case 5:
              alert( '对不起,非法请求位置  获取位置失败.' );
              break;
            case 6:
              alert( '对不起,当前 没有权限 获取位置失败.' );
              break;
            case 7:
              alert( '对不起,服务不可用 获取位置失败.' );
              break;
            case 8:
              alert( '对不起,请求超时 获取位置失败.' );
              break;
          }
        }
      },
      {enableHighAccuracy: true})
    },
    // 测试计算ab两点距离的自定义方法
    // 可能没用
    /*map(){
      let map = new BMap.Map('allmap')
      let point = new BMap.Point(this.center.lng, this.center.lat)
      map.centerAndZoom(point, this.zoom)
      map.enableScrollWheelZoom(true)
      map.enableDoubleClickZoom(true)
      map.addControl(new BMap.NavigationControl());
      var geolocation = new BMap.Geolocation()
      geolocation.getCurrentPosition((r) => {
        if (r.point) {
          this.center.lng = r.longitude
          this.center.lat = r.latitude
          let markers = new BMap.Marker(r.point)
          map.addOverlay(markers)
          map.panTo(r.point)
          map.centerAndZoom(r.point, 16)
          console.log(r.point.lng)
          console.log(r.point.lat)
        }
      }, { enableHighAccuracy: true })    
    },*/
    locationbtn(){
      var map = new BMap.Map('allmap');// 创建地图实例
      var point = new BMap.Point(this.center.lng, this.center.lat);// 创建点坐标
      // console.log(point);//测试
      var geolocation = new BMap.Geolocation();
      // console.log(geolocation);//测试
      geolocation.getCurrentPosition((r) => {
        if (r.point) {
          /*console.log('商家当前经纬度：'+this.center.lng+','+ this.center.lat);//商家坐标（后台传来的数据：目前是假数据）
          console.log('总店当前经纬度：'+this.headCenter.lng+','+this.headCenter.lat);
          console.log('您当前经纬度：'+r.longitude+','+ r.latitude);*/
					//距离差距
          this.distance = this.getDistance(this.center.lng,this.center.lat,r.longitude,r.latitude)
          //console.log(this.distance);//调用计算距离方法，得出两地距离，单位米
          // 通过判断距离确定定位商铺位置
          if(this.distance<5000){
            var point=new BMap.Point( this.center.lng, this.center.lat);
          }else{
            var point=new BMap.Point(this.headCenter.lng,this.headCenter.lat);
          }
          //用当前定位的经纬度查找省市区街道等信息
          var gc = new BMap.Geocoder();
          var that = this;
          gc.getLocation(point, function(rs){
            var addComp = rs.addressComponents; 
            //console.log(rs.address);//地址信息
            // self.locationed = rs.address;
            // 通过判断距离确定店铺名称
            if(that.distance<5000){
              that.locat=rs.address='北京市明日东华商城总店';
              // console.log(that.locat);
            }else{
              that.locat=rs.address='成都天府城广场店';
              // console.log(that.locat);
            }
          });
        }
      },{enableHighAccuracy: true});
    },
    getDistance(lat1,lng1,lat2,lng2) {
      let EARTH_RADIUS = 6378.137;
      let radLat1 = this.rad(lat1);    
        let radLat2 = this.rad(lat2);  
        let a = radLat1 - radLat2;
        let b = this.rad(lng1) - this.rad(lng2);    
        let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)    
                + Math.cos(radLat1) * Math.cos(radLat2)    
                * Math.pow(Math.sin(b / 2), 2)));    
        s = s * EARTH_RADIUS;
        //s = Math.round(s * 10000d) / 10000d;
        s = Math.round(s * 10000) / 10000;
        s = s*1000;    //乘以1000是换算成米
        return s;
    },
    rad(d){
        return d * Math.PI / 180.0;    
    }
  }
};
</script>
<style scoped>
.index {
  background-color: #fff;
}
</style>
